import random
import time
#导入时间
# 空的购物车
mycart = []

# 商品
shop = [
    ["电视机",2500],
    ["洗衣机",1200],
    ["冰箱",1000],
    ["空调",2400],
    ["Mac 电脑",12000],
    ["联想thinkPad e580",4500],
    ["华为 m240青春版",1100],
    ["榴莲",100],
    ["驴肉火烧",10.5],
    ["辣条",5],
    ["可乐",3],
    ["福临门大米",40.5]
]

#优惠券
coupon = [
    ["电视机",9],
    ["电视机",8],
    ["电视机",7],
    ["洗衣机",9],
    ["洗衣机",8],
    ["洗衣机",7],
    ["冰箱",9],
    ["冰箱",8],
    ["空调",9],
    ["空调",8],
]


print("-----------------欢迎来到Jason商城-----------------------")
for a, b in enumerate(shop):  # index = 0 ,  item = [电视机，1000]  展示所有商品序号、名称及价格
    print(a, b)

# 足够的钱
money = input("请输入您的银行卡余额：")
money = int(money)# 强制转化

#随机抽取优惠券
coupon_data = random.randint(0,9)
print(f"恭喜你抽到{coupon[coupon_data][0]}{coupon[coupon_data][1]}折优惠券")

while True:
    num = input("请输入你想要的商品编号：") # num =  6
    if num  ==  "q" or num == "Q":
        print("欢迎下次光临！ ByeBye您嘞！")
        break # 退出循环
    elif num.isdigit():  # "56" --> 56   "a" --->
        num = int(num)
        # 购物
        if num >= len(shop):
            print("对不起，没有这个商品！别瞎弄！")
        else:
            if money >= shop[num][1]:
                flag = 0
                if shop[num][0] == coupon[coupon_data][0] :
                    cost = shop[num][1] * coupon[coupon_data][1] / 10
                else:
                    cost = shop[num][1]
                for i in mycart:
                    if i[0] == shop[num][0]:
                        i[1] = i[1] + 1
                        i[2] = i[2] + cost
                        flag = 1
                        break
                if flag == 0:
                    commodity = [shop[num][0], 1, shop[num][1]]
                    mycart.append([shop[num][0], 1, cost])
                money = money - cost
                print(f"恭喜，购买成功！花费金额:￥{cost}，您的余额还剩:￥{money}")
            else:
                print("穷鬼，钱不足！请到其他地方购买！")
    else:
        print("对不起，输入错误，别瞎弄！请重新输入！")

#  打印购物小条
print("------------------购物小条---------------------")
sum = 0
print("您的购物小条，请拿好：")
print("| 商品 | 数量 | 金额 |")
for i in mycart:
    print(i)
for i in mycart:
    sum = sum +i[2]
print("本次购物总金额：￥",sum)
print("----------------------------------------------")
print("您的本次余额还剩：￥",money,"!")
print(time.asctime())